package com.zz.controller;

import com.zz.common.Log;
import com.zz.common.R;
import com.zz.entity.SystemNotice;
import com.zz.service.SystemNoticeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 通知信息
 * @author HUAWEI
 */
@RestController
@RequestMapping("/systemNotice")
@Slf4j
@CrossOrigin
@Validated
public class SystemNoticeController {

    @Autowired
    private SystemNoticeService systemNoticeService;


    /**
     * 用户查看所有的通知信息
     * */
    @GetMapping("/show")
    @Log(title = "用户查看所有的通知信息", dataLocationType = "link")
    public R<List<SystemNotice>> show(HttpServletRequest request){
        return systemNoticeService.show(request);
    }

    /**
     * 用户查看未读的通知信息
     * */
    @GetMapping("/showUnRead")
    @Log(title = "用户查看未读的通知信息", dataLocationType = "link")
    public R<List<SystemNotice>> showUnRead(HttpServletRequest request){
        return systemNoticeService.showUnRead(request);
    }

    /**
     * 用户查看已读的通知信息
     * */
    @GetMapping("/showRead")
    @Log(title = "用户查看已读的通知信息", dataLocationType = "link")
    public R<List<SystemNotice>> showRead(HttpServletRequest request){
        return systemNoticeService.showRead(request);
    }


    /**
     * 用户删除已读的通知信息
     * */
    @DeleteMapping("/deleteRead")
    @Log(title = "用户删除已读的通知信息", dataLocationType = "link")
    public R<String> deleteRead(@RequestParam @NotNull(message = "通知信息表主键不能为空") int id){
        return systemNoticeService.deleteRead(id);
    }

    /**
     * 设置消息已读
     * */
    @PutMapping("/letRead")
    @Log(title = "设置消息已读", dataLocationType = "link")
    public R<String> letRead(@RequestParam @NotNull(message = "通知信息表主键不能为空") int id){
        return systemNoticeService.letRead(id);
    }
}
